<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var allStr = "HelloWorld";
        var str = "llo";

        //这三个方法都支持第二个参数，表示开始搜索的位置
        //包含
        console.log(allStr.includes(str));   //true
        //必须头部开头
        console.log(allStr.startsWith(str));   //false
        //尾部
        console.log(allStr.endsWith(str));   //true

        //repeat()方法返回一个新字符串，表示将原字符串重复n次
        var x = "x";
       
        console.log(x.repeat(3));
        
        //padEnd和padStart在尾部和头部补全
        console.log(x.padEnd(5,"ab"));
        console.log(x.padStart(5,"ab"));

        //trimStart和trimEnd去掉头部和尾部的空格
        var it = " dafafca ";
        console.log(it.trimStart());
        console.log(it.trimEnd());

        //at()方法接受一个整数作为参数，返回参数指定位置的字符，支持负索引

        var str1 = "afdsvvfas";
        console.log(str1.at(3));
        console.log(str1.at(-4));
    </script>
</body>
</html>